#pragma once

#include "Thread/AbstractApiConnection.h"

#pragma warning(push)
#pragma warning(disable:4100)
#include "FFEX/ThostFtdcTraderApi.h"
#include "FFEX/ThostFtdcMdApi.h"
// #include "FFEX/ThostFtdcMblMdApi.h"
#pragma warning(pop)

#include "FFEX/FFEXTraderHandler.h"
#include "FFEX/FFEXPublicHandler.h"
// #include "FFEX/FFEXMblHandler.h"

class Dealing;
class Cancellation;
class QueueContext;

class FFEXConnection : public AbstractApiConnection
{
public:
	FFEXConnection(Customer const& customer,
		ContractCodes const& contractCodes,
		QueueContext& queueContext,
		std::string const& traderUrl,
		std::string const& marketUrl,
		std::string const& mblUrl);

	virtual void Init();
	virtual void Release();
	virtual void SendOrder(Dealing const& dealing);
	virtual void SendCancellation(Cancellation const& cancellation);
	virtual void SubscribeMarket(char const* contractCode);
	virtual void SubscribePendingMarket(char const* contractCode);
	virtual void QueryMblMarket(char const* contractCode);
private:
	void InitMdApi();
// 	void InitMblApi();
	void InitTraderApi();

	ContractCodes const& m_contractCodes;
	std::string m_traderUrl;
	std::string m_marketUrl;
	std::string m_mblUrl;
	FFEXTraderHandler m_traderHandler;
	FFEXPublicHandler m_publicHandler;
// 	FFEXMblHandler m_mblHandler;
	CThostFtdcTraderApi* m_pTraderApi;
	CThostFtdcMdApi* m_pMdApi;
// 	CThostFtdcMblMdApi* m_pMblApi;

	std::map<std::string,int> m_contractIndexMap;

};
